let app=getApp()
Page({

  data: {
     files:[],arr:[],
     //另一个页面传过来的url
     url:'',goods_id:'',near_id:'',type:'',last:'',file:''
  },

  onLoad: function (options) {
    console.log(options);
    
    console.log(app.globalData.files);
      this.setData({goods_id:options.goods_id,near_id:options.near_id,type:options.type,url:options.url})
      if(options.flag==1){
        this.setData({
          files:[{path:options.file}]
        })
      }
     
  },

    upload(){
      console.log('1');
     
      
     this.throttle(()=>{
      this.getshangchuan()
     },1000)
       
    },
    getshangchuan(){
      wx.showLoading({
        title: '正在上传中',
        icon:'none'
      })
      
      wx.uploadFile({
        filePath: this.data.files[0].path,
        name: 'file',
        url: 'https://zujieba.com/Api/upload/upload.html',
        success:(res)=>{
          wx.hideLoading()
          let data=JSON.parse(res.data)
          console.log(data);
          
          let url="https://zujieba.com/uploads/"+data.name
          // wx.navigateTo({
          //   url: '/pages/fileprint/print/print?near_id='+this.data.near_id+'&goods_id='+this.data.goods_id+"&name="+data.name+
          //   '&time='+data.time+'&page=1'+"&url="+url+'&radio5=3'+"&photo=1"+'&param1=1'
          // })
          wx.navigateTo({
            url: '/pages/fileprint/print/newprint?near_id='+this.data.near_id+'&goods_id='+this.data.goods_id+"&name="+data.name+
            '&time='+data.time+'&page=1'+"&url="+url+'&radio5=3'+"&photo=1"+'&param1=1'
          })
        }})
    
    },
    /*getpdfimage(file){
      wx.request({
        url: 'https://zujieba.com/Api/upload/selectionSplicingToNewPdf.html',
        data:{pdf_road_datas:file},
        method:'POST',
        success:(res)=>{
          console.log(res);
          
          let url="https://zujieba.com/"+res.data.data
          //将图片转为pdf后需要变为临时路径预览
         wx.downloadFile({
           url: url,
           success:(res1)=>{
             console.log(res1);
           
             if(res.data.success==1){
               wx.hideLoading()
              this.throttle(()=>{
                wx.navigateTo({
                  url: '/pages/fileprint/print/print?near_id='+this.data.near_id+'&goods_id='+this.data.goods_id+"&name="+res.data.data+
                  '&time='+res.data.addtime+'&page='+res.data.page+"&url="+url+"&param=1"+'&radio5=3'+'&param1=1'
                })
              },1500)
             
             }else{
               wx.showToast({
                 title: res.data.tips,
                 icon:'none'
               })
             }
             
           }
         })
        
         
          
        }
      })

    },*/
    shanchu(e){
      let arr=this.data.files
      arr.splice(e.currentTarget.dataset.i,1)  
      this.setData({
        files:arr
      })
    },
    bianji(e){
        wx.navigateTo({
          url: '/pages/edit5/edit5?url='+this.data.files[e.currentTarget.dataset.i].path+'&flag=12'+'&index1='+e.currentTarget.dataset.i,
        })
    },
    bianji1(){
      wx.navigateTo({
        url: '/pages/edit5/edit5?url='+this.data.url+'&flag=13'
      })
    },
    upload1(){
     this.throttle(()=>{ console.log('567');
      
     wx.showLoading({
       title: '正在上传中',
       icon:'none'
     })
     wx.uploadFile({
       filePath: this.data.url,
       name: 'file',
       url: 'https://zujieba.com/Api/upload/upload.html',
       success:(res)=>{
           console.log(res);
           let data=JSON.parse(res.data)
           
          
           this.getliucun(data.name)
          

           
       },
      
     })},1500)
    },
    //6cun7寸的接口
    getliucun(file){
        wx.request({
          url: 'https://zujieba.com/Api/upload/photo.html',
          data:{type:this.data.type,pic:file,goods_id:this.data.goods_id},
          method:'POST',
          success:(res)=>{
            wx.hideLoading()
            console.log(res);
            let url='https://zujieba.com/uploads/'+res.data.data
            // wx.navigateTo({
            //   url: '/pages/fileprint/print/print?near_id='+this.data.near_id+'&goods_id='+this.data.goods_id+"&name="+res.data.data+
            //   '&time='+res.data.time+"&url="+url+'&photo=1'
            // })  
            wx.navigateTo({
              url: '/pages/fileprint/print/newprint?near_id='+this.data.near_id+'&goods_id='+this.data.goods_id+"&name="+res.data.data+
              '&time='+res.data.time+"&url="+url+'&photo=1'+'&phototrue=1'+"&printtype="+this.data.type
            })  
          }
        })
    },
    //节流
    throttle:function(func,wait){
      console.log(func,wait);
      
      let last =this.data.last
      console.log(last);
      
      let current_time= +new Date()
      if(current_time-last>wait){
        console.log(1111);
          console.log(current_time,current_time-last);
          
          func()
          last=+new Date()
          this.setData({
            last
          })
      }
        
         
      
       
    },
    upload2(){
     this.throttle(()=>{ console.log("quantu");
      
     wx.showLoading({
       title: '正在上传中',
       icon:'none'
     })
     wx.uploadFile({
       filePath: this.data.url,
       name: 'file',
       url: 'https://zujieba.com/Api/upload/upload.html',
       success:(res)=>{
         wx.hideLoading()
           console.log(res);
           let data=JSON.parse(res.data)
           let url='https://zujieba.com/uploads/'+data.name
        
          //  wx.navigateTo({
          //    url: '/pages/fileprint/print/print?near_id='+this.data.near_id+'&goods_id='+this.data.goods_id+"&name="+data.name+
          //    '&time='+data.time+"&url="+url+"&radio5=3"+"&photo=1"+'&param=1'+'&param1=1'
          //  })  
          wx.navigateTo({
            url: '/pages/fileprint/print/newprint?near_id='+this.data.near_id+'&goods_id='+this.data.goods_id+"&name="+data.name+
            '&time='+data.time+"&url="+url+"&radio5=3"+"&photo=1"+'&param=1'+'&param1=1'+'&phototrue=1'
          })
           
          

           
       },
       fail:(res)=>{
         wx.hideLoading()
       }
     })},1500)
    },
  
})